//
//  BLHotelCustomViewController.m
//  blanket
//
//  Created by Mac on 2017/12/6.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLHotelCustomViewController.h"
#import "BLHotelCustomTableViewCell.h"
#import "UIButton+STPhotoKitSelectedAnimation.h"
#import "BLCustomModel.h"
#import "BLShopCarViewController.h"
#import "BLGoodBuyViewController.h"
#import "STAddressModel.h"
@interface BLHotelCustomViewController ()<STActionSheetDelegate>
@property(nonatomic, strong) STAddressModel                     *addModel;
@property(nonatomic, strong) STButton                     *shopButton;//购物车
@property(nonatomic, strong) STLabel                     *moneyLable;//金额
@property(nonatomic, strong) STButton                     *testButton;//线下送样
@property(nonatomic, strong) STButton                     *cofrimButton;//购买或者删除

@property(nonatomic, strong) NSMutableArray                     *dataSouce;
@property(nonatomic, weak) NSURLSessionDataTask                     *task;
@end

@implementation BLHotelCustomViewController


#pragma mark --vc 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
//    self.title = @"布草定制";
    //制造空footer ，适配键盘
    UIView * tableFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, [TMUtils tabbar].height)];
    tableFooter.backgroundColor = self.tableView.backgroundColor;
    self.tableView.tableFooterView = tableFooter;
    [self.tableView st_autoAdjustAllResponder];
    [self configBootomeView];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self sendCustomRequest];
    }];
    [self.tableView.mj_header beginRefreshing];
    [self sendFetchDefultAddRequuest];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self sendFetchDefultAddRequuest];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
- (void)configBootomeView{
    UIView  * bootomView = [[UIView alloc] initWithFrame:CGRectMake(0, [TMUtils tabbar].top, UIScreenWidth, [TMUtils tabbar].height)];
    bootomView.bottom = UIScreenHeight;
    bootomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bootomView];
    [bootomView st_showTopShadow];
    [bootomView st_showBottomLine];
    __weak typeof(self) weakSelf =  self;
    self.shopButton = [[STButton alloc] initWithFrame:CGRectMake(10, 0, 44, 49)
                                               title:@""
                                          titleColor:KL_firstTextColor
                                           titleFont:14
                                        cornerRadius:0
                                     backgroundColor:nil
                                     backgroundImage:nil
                                               image:[UIImage imageNamed:@"购物车"]];
    self.shopButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    [self.shopButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedShopCarButton];
    }];
    [bootomView addSubview:self.shopButton];
    
    self.cofrimButton = [[STButton alloc] initWithFrame:CGRectMake(0, 7, 80, 35)
                                                  title:@"立即定制"
                                             titleColor:[UIColor whiteColor]
                                              titleFont:15
                                           cornerRadius:8
                                        backgroundColor:KL_BlueBackGroundColor
                                        backgroundImage:nil
                                                  image:nil];
    self.cofrimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.cofrimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedConfimButton];
    }];
    self.cofrimButton.right = UIScreenWidth - 10;
    [bootomView addSubview:self.cofrimButton];
    
    self.testButton = [[STButton alloc] initWithFrame:CGRectMake(0, 7, 80, 35)
                                                  title:@"线下送样"
                                             titleColor:[UIColor whiteColor]
                                              titleFont:15
                                           cornerRadius:8
                                        backgroundColor:KL_BlueBackGroundColor
                                        backgroundImage:nil
                                                  image:nil];
    self.testButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.testButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedtestButton];
    }];
    self.testButton.right = self.cofrimButton.left - 10;
    [bootomView addSubview:self.testButton];
    
    self.moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(self.shopButton.right + 10, 0, self.testButton.left - self.shopButton.right - 20, 49)
                                                text:@"合计:$0:00"
                                           textColor:KL_redColor
                                                font:13
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    self.moneyLable.attributedText = [self.moneyLable.text st_convertAttributeStringWithKeyWord:@"合计:"
                                                                                     attributes:@{NSForegroundColorAttributeName:KL_firstTextColor}];
    [bootomView addSubview:self.moneyLable];
    
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [BLHotelCustomTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    BLHotelCustomTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[BLHotelCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    __weak typeof(self) weakSelf =  self;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.dataSouce[indexPath.row];
    [cell.addButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedAddCarButton:indexPath];
    }];
    [cell.chosedButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedChosedButton:indexPath];
    }];
    [cell setChangKuanDidEndEditing:^(NSString *chang, NSString *kuan) {
        [weakSelf caclutePriceFormWithIndexPath:indexPath chang:chang kuan:kuan];
    }];
    [cell setQulityButtonDidChanged:^(BLMassModel *model) {

        [weakSelf onSelectedMassButton:indexPath];
    }];

    [cell.autoAddView setAutoAddViewNumChanged:^(NSInteger num) {
        [weakSelf onChangedValueAutoAddViewWithIndexPath:indexPath num:num];
    }];
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Private Method
- (void)reloadData{
    [self.tableView reloadData];
}
- (void)cacluteCurrentAllMoney{
    CGFloat money = 0;
    for (BLCustomModel * model in self.dataSouce) {
        if (model.selected) {
            money = money + model.member_money.floatValue * model.num.integerValue;
        }
    }
    self.moneyLable.text = [NSString stringWithFormat:@"合计:%0.2f",money];
    self.moneyLable.attributedText = [self.moneyLable.text st_convertAttributeStringWithKeyWord:@"合计:" attributes:@{NSForegroundColorAttributeName:KL_firstTextColor}];
}
- (BLCustomModel*)currentSleectedModel{
    for (BLCustomModel * model in self.dataSouce) {
        if (model.selected) {
            return model;
        }
    }
    return nil;
}
#pragma mark --Action Method
- (void)onSelectedtestButton{
    BLCustomModel *  model = [self currentSleectedModel];
    if (!model) {
        [SVProgressHUD showErrorWithStatus:@"您还未选择商品"];
        return ;
    }
    if (!model.chang.length || !model.kuan.length ) {
        [SVProgressHUD showErrorWithStatus:@"你还未选择尺寸"];
        return;
    }
    [self sendGoodOffLineRequest];
}
- (void)onSelectedConfimButton{
    BLCustomModel *  model = [self currentSleectedModel];
    
    if (!model) {
        [SVProgressHUD showErrorWithStatus:@"您还未选择商品"];
        return ;
    }
    if (!model.chang.length || !model.kuan.length ) {
        [SVProgressHUD showErrorWithStatus:@"你还未选择尺寸"];
        return;
    }
    BLShopCarModel * shopmodel = [BLShopCarModel new];
    shopmodel.width = model.kuan;
    shopmodel.leng = model.chang;
    shopmodel.name = model.name;
    shopmodel.price = model.member_money;
    shopmodel.num = model.num.description;
    shopmodel.grade = model.grade;
    shopmodel.make_score = model.score;
    shopmodel.type = @"2";
    shopmodel.score_money = model.score_money;
    BLGoodBuyViewController  *goodBuy =  [BLGoodBuyViewController new];
    goodBuy.shopModel = shopmodel;
    goodBuy.allMoneyDesc = self.moneyLable.text;
    
    [self.navigationController pushViewController:goodBuy animated:YES];

   
}
- (void)showActionSheet{
    BLCustomModel *  model = [self currentSleectedModel];
    NSString * jifenzhifubao = [NSString stringWithFormat:@"您将支付宝支付￥%0.2f元 + %0.2f积分",
                                model.score_money.floatValue * model.num.integerValue,
                                model.score.floatValue * model.num.integerValue];
    NSString * jifenwechat = [NSString stringWithFormat:@"您将微信支付￥%0.2f元 + %0.2f 积分",
                              model.score_money.floatValue * model.num.integerValue,
                              model.score.floatValue * model.num.integerValue];
    NSString * zhifubao = [NSString stringWithFormat:@"您将支付宝支付￥%0.2f 元",model.member_money.floatValue  * model.num.integerValue];
    NSString * wechat = [NSString stringWithFormat:@"您将微信支付￥%0.2f 元",model.member_money.floatValue * model.num.integerValue];
    STActionSheet * action = [[STActionSheet alloc] initWithTitle:@"支付方式"
                                                     buttonTitles:@[jifenzhifubao,jifenwechat,zhifubao,wechat]
                                                      cancelTitle:@"取消"
                                                         delegate:self];
    [action show];
}
- (void)onSlectedShopCarButton{
    [self.navigationController pushViewController:[BLShopCarViewController new] animated:YES];
}
- (void)onChangedValueAutoAddViewWithIndexPath:(NSIndexPath*)indexPath num:(NSInteger)num{
    BLCustomModel *  model = self.dataSouce[indexPath.row];
    model.num = @(num);
    [self cacluteCurrentAllMoney];
}
- (void)onSelctedAddCarButton:(NSIndexPath*)indexPath{
    BLCustomModel *  model = self.dataSouce[indexPath.row];
    
    if (!model.chang.length || !model.kuan.length ) {
        [SVProgressHUD showErrorWithStatus:@"你还未选择尺寸"];
        return;
    }
    if (model.chang.length && model.kuan.length && [model.member_money integerValue] == 0) {
        [SVProgressHUD showErrorWithStatus:@"正在请求价格请稍后"];
        return;
    }
    [self sendAddToCarShopRequestWithModel:model];
}
- (void)onSelctedChosedButton:(NSIndexPath*)indexPath{
      BLCustomModel *  model = self.dataSouce[indexPath.row];
    for (BLCustomModel * existModel in self.dataSouce) {
        if (existModel.selected) {
            existModel.selected = NO;
            NSInteger index = [self.dataSouce indexOfObject:existModel];
            NSIndexPath * existModelIndexPath = [NSIndexPath indexPathForRow:index inSection:0];
            [self.tableView reloadRowsAtIndexPaths:@[existModelIndexPath] withRowAnimation:UITableViewRowAnimationNone];
        }
    }
     model.selected = YES;
     [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [self cacluteCurrentAllMoney];
}
- (void)onSelectedMassButton:(NSIndexPath*)indexPath{
    BLCustomModel *  model = self.dataSouce[indexPath.row];
    if (model.chang.length && model.kuan.length) {
        [self caclutePriceFormWithIndexPath:indexPath chang:@"" kuan:@""];
    }
    [self cacluteCurrentAllMoney];
}
#pragma mark --Private Method
- (NSMutableDictionary *)defultDic{
    BLCustomModel * model = [self currentSleectedModel];
    if (!model) {
        [SVProgressHUD showErrorWithStatus:@"您还未选择商品"];
        return nil;
    }
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    if (model.goodID.length) {
        [dic setObject:model.goodID forKey:@"gid"];
    }
    if (model.chosedMassModel.massID) {
        [dic setObject:model.chosedMassModel.massID forKey:@"mass_id"];
    }
    if (model.kuan.length) {
        [dic setObject:model.kuan forKey:@"width"];
    }
    if (model.chang.length) {
        [dic setObject:model.chang forKey:@"length"];
    }
    CGFloat  money = 0;
    money = money + model.member_money.floatValue * model.num.integerValue;
    [dic setObject:@(money) forKey:@"price"];
    if (model.num) {
        [dic setObject:model.num forKey:@"num"];
    }
    
    if (model.grade) {
        [dic setObject:model.grade forKey:@"grade"];
    }
    
    if (model.score) {
        [dic setObject:model.score forKey:@"score"];
    }
    return dic;
}
#pragma mark --STActionSheetDeLlegate
- (void)actionSheet:(STActionSheet *)actionSheet didClickedButtonAtIndex:(NSInteger)buttonIndex{
    if (actionSheet.titleArray.count <= buttonIndex) {
        //点击取消
        return;
    }
    
    NSMutableDictionary * dic = [self defultDic];
    BLCustomModel * model =   [self currentSleectedModel];
    //积分 支付宝微信  -- 微信支付宝微信
    if (buttonIndex == 0) {
        [dic setObject:@"2" forKey:@"type"];
        [dic setObject:@"2" forKey:@"pay_type"];
       
        [dic setObject:model.score_money forKey:@"price"];
    }
    if (buttonIndex == 1) {
        [dic setObject:@"2" forKey:@"type"];
        [dic setObject:@"3" forKey:@"pay_type"];
        [dic setObject:model.score_money forKey:@"price"];
    }
    if (buttonIndex == 2) {
        
        [dic setObject:@"1" forKey:@"type"];
        [dic setObject:@"2" forKey:@"pay_type"];
    }
    if (buttonIndex == 3) {
        
        [dic setObject:@"1" forKey:@"type"];
        [dic setObject:@"3" forKey:@"pay_type"];
    }
    [self sendBuyNowRequest_version_twoWithDic:dic];
}
#pragma mark --NetWork Method
- (void)sendCustomRequest{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/madeLinenAction"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    [dic setObject:@"1" forKey:@"type"];
    
    if (self.subtype.length) {
        [dic setObject:self.subtype forKey:@"subtype"];
    }
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 NSArray * dataArray =  responseObject[@"data"];
                                                 self.dataSouce = [NSMutableArray new];
                                                 
                                                 for (NSDictionary * dicModel in dataArray) {
                                                     BLCustomModel * model = [BLCustomModel mj_objectWithKeyValues:dicModel];
                                                     NSArray * mass = dicModel[@"mass"];
                                                     NSMutableArray * massArray = [NSMutableArray new];
                                                     for (NSDictionary * massDIc in mass) {
                                                         BLMassModel * massModel = [BLMassModel mj_objectWithKeyValues:massDIc];
                                                         [massArray addObject:massModel];
                                                     }
                                                     model.mass = massArray;
                                                     [self.dataSouce addObject:model];
                                                 }
                                                 NSLog(@"json = %@",dataArray.mj_JSONString);
                                                 [self reloadData];

                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
- (void)sendAddToCarShopRequestWithModel:(BLCustomModel*)model{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/shoppingCardAction"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }

    if (model.goodID) {
        [dic setObject:model.goodID forKey:@"gid"];
    }
    [dic setObject:@"2" forKey:@"type"];
    
    if (model.name.length) {
        [dic setObject:model.name forKey:@"name"];
    }
    if (model.member_money) {
        [dic setObject:model.member_money forKey:@"price"];
    }
    if (model.num) {
        [dic setObject:model.num forKey:@"num"];
    }
    [dic setObject:@"1" forKey:@"state"];
    
    if (model.chosedMassModel.massID) {
         [dic setObject:model.chosedMassModel.massID forKey:@"spec_id"];
    }
    
    if (model.chang.length) {
        [dic setObject:model.chang forKey:@"leng"];
    }
    if (model.kuan.length) {
        [dic setObject:model.kuan forKey:@"width"];
    }
    //新家三个字段
    if (model.member_money) {
        [dic setObject:model.score_money forKey:@"score_money"];
    }
    if (model.score) {
        [dic setObject:model.score forKey:@"make_score"];
    }
    if (model.grade) {
        [dic setObject:model.grade forKey:@"grade"];
    }
    
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showSuccessWithStatus:@"添加到购物车成功"];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}

- (void)caclutePriceFormWithIndexPath:(NSIndexPath*)indexPath chang:(NSString*)chang kuan:(NSString*)kuan{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/reckonMadeGoodsPrice"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    BLCustomModel *  model = self.dataSouce[indexPath.row];
    if (model.chosedMassModel.massID) {
        [dic setObject:model.chosedMassModel.massID forKey:@"mass_id"];
    }
    if (model.chang.length) {
        [dic setValue:model.chang forKey:@"length"];
    }else{
        [SVProgressHUD showErrorWithStatus:@"您还未输入长度"];
        return;
    }
    if (model.kuan.length) {
        [dic setValue:model.kuan forKey:@"width"];
    }else{
        [SVProgressHUD showErrorWithStatus:@"您还未输入宽度"];
        return;
    }
    if (model.goodID.length) {
       [dic setValue:model.goodID forKey:@"made_id"];
    }

    [self.task cancel];
   _task =  [[STNetWrokManger defaultClient] taskRequestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * dataDic =  responseObject[@"data"];
                                                 
                                                 model.member_money = dataDic[@"member_money"];
                                                 model.grade = dataDic[@"grade"];
                                                 model.score = dataDic[@"score"];
                                                 model.score_money = dataDic[@"score_money"];
                                                 
                                                 [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
                                                  [self cacluteCurrentAllMoney];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
//线下 送样
- (void)sendGoodOffLineRequest{
    BLCustomModel * model = [self currentSleectedModel];
    if (!model) {
        [SVProgressHUD showErrorWithStatus:@"您还未选择商品"];
        return;
    }
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/promptlyMade"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    if (model.goodID.length) {
        [dic setObject:model.goodID forKey:@"gid"];
    }
    if (model.chosedMassModel.massID) {
        [dic setObject:model.chosedMassModel.massID forKey:@"mass_id"];
    }
    if (model.kuan.length) {
        [dic setObject:model.kuan forKey:@"width"];
    }
    if (model.chang.length) {
        [dic setObject:model.chang forKey:@"length"];
    }
    if (model.member_money) {
         [dic setObject:model.chang forKey:@"price"];
    }
    if (model.num) {
        [dic setObject:@"1" forKey:@"num"];
    }
    [dic setObject:@"1" forKey:@"type"];

    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showSuccessWithStatus:@"线下送样成功"];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
//立即定制- 新版
- (void)sendBuyNowRequest_version_twoWithDic:(NSMutableDictionary*)dic{
    
    
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/makePromptlyAction"];
     NSString * type = dic[@"pay_type"];
    if (self.addModel) {
        if (self.addModel.address.length) {
            [dic setObject:self.addModel.address forKey:@"address"];
        }
        if (self.addModel.mobile.length) {
            [dic setObject:self.addModel.mobile forKey:@"mobile"];
        }
        if (self.addModel.username.length) {
            [dic setObject:self.addModel.username forKey:@"username"];
        }
    }
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 NSString * order =  responseObject[@"data"];
                                                 if([type isEqualToString:@"2"]){
                                                     //支付宝
                                                     [TMUtils sendAliPayWithOrder:order];
                                                     
                                                 }else if([type isEqualToString:@"3"]){
                                                     //微信
                                                     [TMUtils sendWechatPayWithOrder:order];
                                                     
                                                 }
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
- (void)sendFetchDefultAddRequuest{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/userDefaultAddress"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSString * modelDic =  responseObject[@"data"];
                                                 self.addModel = [STAddressModel mj_objectWithKeyValues:modelDic];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
@end
